/**
 * Copyright ©2012-2018 HopeHaiyang Corporation, All Rights Reserved
 * http://www.wuhanhope.com
 */
package hope.platform.data.server.img;

import hope.platform.data.dao.TyphoonInfoRepository;
import hope.platform.data.domain.Typhoon;
import hope.platform.data.server.header.TyphoonInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

/**
 * class info
 * @author Lizhangqing
 * @see TyphoonInfoService
 * @since
 * Create at 2018/7/23
 */
@Service
public class TyphoonInfoServiceImg implements TyphoonInfoService {
    @Autowired
    private TyphoonInfoRepository typhoonInfoRepository;

    @Override
    public List<Typhoon> getTyphoonInfoByTfbh(String tfbh) {
        return typhoonInfoRepository.findByTfbh(tfbh);
    }

    @Override
    public List<Typhoon> getTyphoonInfoByYear(Integer year) {
        List<Typhoon> typhoonList = typhoonInfoRepository.findByYear(year);
        Set<String> tfbh = new TreeSet<>();
        List<Typhoon> retTyphoonList = new ArrayList<>();
        for (Typhoon typhoon : typhoonList) {
            if (tfbh.contains(typhoon.getTfbh())) continue;
            tfbh.add(typhoon.getTfbh());
            retTyphoonList.add(typhoon);
        }
        return retTyphoonList;
    }
}
